import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LC3115
 * @Author ykx
 * @Date 2024/7/2 20:25
 * @Version 1.0
 */
public class LC3115 {
    public static void main(String[] args) {
        LC3115 lc3115 = new LC3115();
        System.out.println(lc3115.maximumPrimeDifference(new int[]{1, 7}));
    }

    public int maximumPrimeDifference(int[] nums) {
        int first = 0, last = nums.length - 1;
        for (int i = 0; i < nums.length; i++) {
            if (isPrime(nums[i])) {
                first = i;
                break;
            }
        }

        for (int i = nums.length - 1; i >= 0; i--) {
            if (isPrime(nums[i])) {
                last = i;
                break;
            }
        }
        return last - first;
    }

    public boolean isPrime(int num) {
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(3);
        list.add(5);
        list.add(7);
        return list.contains(num) || num > 1 && num % 2 != 0 && num % 3 != 0 && num % 5 != 0 && num % 7 != 0;

    }

}
